package com.djl.spring.redis.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/client")
public class RedisController {

    @Autowired
    RedisTemplate redisTemplate;

    @GetMapping("/sendMessage")
    public String sendMessage(String key,String val){
        try {
            redisTemplate.opsForValue().set(key,val);
        }catch (Exception e){
            e.printStackTrace();
            return "网络服务异常请稍后再试!";
        }
        return "ok";
    }

    @GetMapping("/getMessage")
    public String getMessage(String key){
        return (String) redisTemplate.opsForValue().get(key);
    }

}
